﻿@model IEnumerable<HanGu.Entity.MemberInfo>
@{
    Layout = null;
    int i = 1;
    ViewBag.ViewTitle = "客户基本信息";
    var SearchParma = ViewData["SearchParma"] as HanGu.Entity.UniversallySearchParam;
    var MemberGrade = ViewData["MemberGrade"] as SelectList;
    var Degree = ViewData["Degree"] as SelectList;
    var SexList = ViewData["SexList"] as SelectList;
    string lookup = Request["lookup"];
    string formCallback = "navTabSearch(this)";
    if (!string.IsNullOrEmpty(lookup))
    {
        formCallback = "dwzSearch(this, 'dialog')";
    }
    var eamilMembers = Model.Where(c => c.NoEmail && !string.IsNullOrEmpty(c.Email)).ToList();
    var smsMembers = Model.Where(c => c.NoSMS && !string.IsNullOrEmpty(c.Tel)).ToList();
    var emailsCount = eamilMembers.Count();
    var smsCount = smsMembers.Count();
    var totalCount = Model.Count();
    TempData["SelectedSMSMembers"] = smsMembers;
    TempData["SelectedEmailsMembers"] = eamilMembers;
}
<script>
    function selectedCheckBox(obj) {
        var checkbox = $(obj).find(':checkbox');
        var isChecked = checkbox.attr("CHECKED") == "checked";
        checkbox.attr("checked", !isChecked);
    }


    function SendSMS(obj) {
        $this = $(obj);
        var membersIDs = "@eamilMembers";
        //        var membersIDs = new Array();
        //        $.each($("input[name='MembersToSelectForMsg']:checked"), function (i, item) {
        //            membersIDs.push($(item).attr("value"));
        //        });
        if (membersIDs == null || membersIDs.length == 0) {
            alertMsg.error("未选择任何客户或所选择的客户不接收短信!");
        }
        else {
            var newUrl = $this.attr("ref");
            navTab.openTab("SendMessage", newUrl, { title: "发送短信", fresh: true, data: { membersID: 'temp', SendingCount: '@smsCount'} });
        }
        return false;
    }
    function SendEmail(obj) {
        $this = $(obj);
        var membersIDs = "@smsMembers";
        //        var membersIDs = new Array();
        //        $.each($("input[name='MembersToSelectForMsg']:checked"), function (i, item) {
        //            membersIDs.push($(item).attr("value"));
        //        });
        if (membersIDs == null || membersIDs.length == 0) {
            alertMsg.error("未选择任何客户或所选择的客户不接收邮件!");
        }
        else {
            var newUrl = $this.attr("ref");
            navTab.openTab("SendMessage", newUrl, { title: "发送邮件", fresh: true, data: { membersID: 'temp', SendingCount: '@emailsCount'} });
        }
        return false;
    }
</script>
<div layouth="10">
    <div class="pageHeader">
        <form id="pagerForm" method="get" action="/CustomerInfo/Default/index?action=page&OpID=@ViewData["OperateID"]">
        <input type="hidden" name="pageNum" value="1" />
        <input type="hidden" name="numPerPage" value="@ViewData["pageSize"]" />
        <input type="hidden" name="RowCount" value="@ViewData["RowCount"]" />
        <input type="hidden" name="orderField" value="${param.orderField}" />
        <input type="hidden" name="Title" value="@SearchParma.Ttile" />
        <input type="hidden" name="Suitabler" value="@SearchParma.Suitabler" />
        <input type="hidden" name="Lectcher" value="@SearchParma.Lectcher" />
        <input type="hidden" name="PalayAdress" value="@SearchParma.PalayAdress" />
        <input type="hidden" name="Degree" value="@SearchParma.Degree" />
        <input type="hidden" name="StarTime" value="@SearchParma.StarDateTime" />
        <input type="hidden" name="EndTime" value="@SearchParma.EndDateTime" />
        <input type="hidden" name="lookup" value="@lookup" />
        <input type="hidden" name="IsBacklist" value="@SearchParma.IsBacklist" />
        <input type="hidden" name="Sex" value="@SearchParma.Sex" />
        <input type="hidden" name="Tel" value="@SearchParma.Tel" />
        <input type="hidden" name="NativePlace" value="@SearchParma.NativePlace" />
        <input type="hidden" name="IsMarry" value="@SearchParma.IsMarry" />
        <input type="hidden" name="HasChildren" value="@SearchParma.HasChildren" />
        <input type="hidden" name="Provice" value="@SearchParma.Provice" />
        <input type="hidden" name="City" value="@SearchParma.City" />
        <input type="hidden" name="Oganization" value="@SearchParma.Oganization" />
        <input type="hidden" name="ChargeRandS" value="@SearchParma.ChargeRandS" />
        <input type="hidden" name="ChargeRandE" value="@SearchParma.ChargeRandE" />
        <input type="hidden" name="ContractRandS" value="@SearchParma.ContractRandS" />
        <input type="hidden" name="ContractRandE" value="@SearchParma.ContractRandE" />
        <input type="hidden" name="ContractNumRandS" value="@SearchParma.ContractNumRandS" />
        <input type="hidden" name="ContractNumRandE" value="@SearchParma.ContractNumRandE" />
        <input type="hidden" name="ImportantLevel" value="@SearchParma.ImportantLevel" />
        <input type="hidden" name="AssignedIn" value="@SearchParma.AssignedIn" />
        <input type="hidden" name="Groups" value="@SearchParma.Groups" />
        <input type="hidden" name="IsPage" value="@SearchParma.IsPage" />
        </form>
        <div id="SelectorHighSearch">
            @Html.Action("HighSeach", "Default", new { area = "CustomerInfo" })
        </div>
    </div>
    <div class="pageContent">
        <div class="panelBar">
            <ul class="toolBar" style="text-align: right">
                <li><a class="add" href='#' ref="/Message/Default/Email/" rel="SendMessage" title="共[@emailsCount]客户可接收邮件"
                    onclick="return SendEmail(this)"><span>群发邮件(@emailsCount)</span></a></li>
                <li><a class="add" href='#' ref="/Message/Default/SMS/" rel="SendMessage" title="共[@smsCount]客户可接收短信"
                    onclick="return SendSMS(this)"><span>群发短信(@smsCount)</span></a></li>
                <li><span style="color: Red">共搜索到记录：@totalCount</span></li>
            </ul>
        </div>
        @*<table class="table" width="100%">
            <thead>
                <tr class="header">
                    <th>
                        序号
                    </th>
                    <th>
                        姓名
                    </th>                
                    <th>
                        手机
                    </th>
                    <th>
                        Email
                    </th>
                    <th>
                        归属用户
                    </th>
                    <th>
                        <input type="checkbox" class="checkboxCtrl" group="MembersToSelectForMsg" checked="true" />全选
                    </th>
                </tr>
            </thead>
            @foreach (var item in Model)
            {            
                <tr id="memberItem" target="CustomerInfo_id" rel="@item.ID/@item.GUID" itemID="@item.ID" nosms="@item.NoSMS" noemail="@item.NoEmail" tel="@item.Tel" email="@item.Email" style="@(item.IsNew ? "color:Red" : string.Empty)" onclick="selectedCheckBox(this)">
                    <td>
                        @i
                    </td>
                    <td>
                        @item.RealName
                    </td>                    
                    <td>
                        @if (item.NoSMS)
                        {
                            @item.Tel
                        }
                        else
                        { 
                            <span style="font-weight: bold">不接收信息</span>
                        }
                    </td>
                    <td>
                        @if (item.NoEmail)
                        {
                            @item.Email
                        }
                        else
                        { 
                            <span style="font-weight: bold">不接收邮件</span>
                        }
                    </td>
                    <td>
                        @{
                        var managers = string.Join(" ", item.MemberAssignedManagers.Select(c => c.RealName + c.User));
                            @managers            
                        }
                    </td>
                    <td>
                        <input  type="checkbox" id="MembersToSelectForMsg" name="MembersToSelectForMsg" tel='@(item.NoSMS ? item.Tel : string.Empty)'  email="@(item.NoEmail ? item.Email : string.Empty)" value="@item.ID" Username='@item.UserName'  disabled=disabled checked="true"/>
                    </td>
                </tr>
                        i += 1;
            }
        </table>*@
    </div>
</div>
